//
//  RadioButton.swift
//  FM
//
//  Created by x on 2017/8/31.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

class RadioButton: UIButton {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        titleLabel?.textAlignment = NSTextAlignment.center
        titleLabel?.font = UIFont.systemFont(ofSize: 12)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        imageView?.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.width)
        imageView?.layer.cornerRadius = bounds.width/2
        imageView?.layer.masksToBounds = true
        titleLabel?.frame  = CGRect(x: 0, y: bounds.width, width: bounds.width, height: bounds.height-bounds.width)
    }
    
        
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}


extension RadioButton {
    class func creatRadioButton(tag:Int, target:Any?, action:Selector) -> RadioButton {
        
        let btu  = RadioButton()
        btu.tag = tag
        btu.setTitleColor(UIColor.black, for: UIControlState.normal)
        btu.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        
        return btu
    }
}
